﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ProjectWebNhac.DTO;
using ProjectWebNhac.DAO;
using System.Data;

namespace ProjectWebNhac.BUS
{
    public class NguoiDungBus
    {
        NguoiDungDTO nddto = new NguoiDungDTO();
        Dataprovider dao = new Dataprovider();
        public bool RegisterUser(NguoiDungDTO nddto)
        {
            object[] para= {"@TaiKhoan",nddto.TaiKhoan,"@HoTen",nddto.HoTen,"@MatKhau",nddto.MatKhau,"@Email",nddto.Email};
            bool kq = dao.XuLySuKien("sp_User_NguoiDungDangKy", CommandType.StoredProcedure, para);
            return kq;
        }

        public DataTable LoginUser(NguoiDungDTO nddto)
        {
            object[] para = { "@TaiKhoan", nddto.TaiKhoan, "@MatKhau", nddto.MatKhau };
            DataTable dt = dao.LayDuLieuThamSo("sp_User_NguoiDungLogin", CommandType.StoredProcedure, para);
            if (dt.Rows.Count > 0)
            {
                nddto.TaiKhoan=dt.Rows[0]["TaiKhoan"].ToString(); 
                nddto.Avatar=dt.Rows[0]["Avatar"].ToString(); 
                nddto.Email=dt.Rows[0]["Email"].ToString(); 
                nddto.HoTen=dt.Rows[0]["HoTen"].ToString(); 
                nddto.MatKhau=dt.Rows[0]["MatKhau"].ToString();
               // nddto.NgayDangKy = DateTime.Parse(dt.Rows[0]["NgayDangKy"].ToString());
               // nddto.NgaySinh = DateTime.Parse(dt.Rows[0]["NgaySinh"].ToString());
                nddto.GioiTinh = Convert.ToBoolean(dt.Rows[0]["GioiTinh"]);
                HttpContext.Current.Session["ThanhVien"] = nddto;
            }
            return dt;
        }

        public DataTable LayThongTinNguoiDung(NguoiDungDTO nddto)
        {
            object[] para = { "@TaiKhoan", nddto.TaiKhoan };
            DataTable dt = dao.LayDuLieuThamSo("sp_User_LayNguoiDung", CommandType.StoredProcedure, para);
            return dt;
        }

        public bool DoiMatKhau(string TaiKhoan , string matkhaucu, string matkhaumoi)
        {
            object[] para = { "@TaiKhoan", TaiKhoan, "@MatKhauCu", matkhaucu, "@MatKhauMoi", matkhaumoi };
            bool kq = dao.XuLySuKien("sp_User_DoiMatKhau", CommandType.StoredProcedure, para);
            return kq;
        }
       
        public bool ThayDoiThongTin(NguoiDungDTO objNguoiDung)
        {
            return dao.XuLySuKien("sp_User_ThayDoiThongTin", CommandType.StoredProcedure,
                new object[] {"@GioiTinh",objNguoiDung.GioiTinh,"@Ten",objNguoiDung.HoTen,
                "@NgaySinh",objNguoiDung.NgaySinh,"@Avartar",objNguoiDung.Avatar,
                "@TaiKhoan",objNguoiDung.TaiKhoan });
        }

        public DataTable LayDanhSachNguoiDung()
        {
            DataTable dt = dao.LayDuLieuThamSo("sp_Admin_LayDanhSachThanhVien", CommandType.StoredProcedure);
            return dt;
        }

        public bool KhoaMoUser(string TaiKhoan, int TrangThai)
        {
            object[] para = { "@TaiKhoan", TaiKhoan, "@TrangThai", TrangThai };
            bool kq = dao.XuLySuKien("sp_Admin_KhoaMoUser", CommandType.StoredProcedure, para);
            return kq;
        }
    }
}